package com.zb.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Strings;
import com.zb.entity.TbAlarmModel;
import com.zb.entity.TbQuotaModel;
import com.zb.service.TbAlarmService;
import com.zb.util.R;
import com.zb.vo.AlarmPageVO;
import com.zb.emq.EmqClient;
import com.zb.vo.QuotaPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName TbAlarmController
 * @Description 控制器
 * @Author xm
 * @Date 2024/08/08 10:15
 **/
@RestController
@RequestMapping("/tb-alarm-model")
@Api(value = "TbAlarmController", tags = {"控制器"})
public class TbAlarmController {

    @Autowired
    public TbAlarmService tbAlarmModelService;

//分页
    @PostMapping("/page")
    public R page(@RequestBody AlarmPageVO alarmPageVO) {
        LambdaQueryWrapper<TbAlarmModel> qw = new LambdaQueryWrapper<>();
        if (!Strings.isNullOrEmpty(alarmPageVO.getName())) {
            qw.like(TbAlarmModel::getName, alarmPageVO.getName());
        }
        Page<TbAlarmModel> page = new Page<>(alarmPageVO.getIndex(), alarmPageVO.getSize());
        tbAlarmModelService.page(page, qw);
        System.out.println(page);
        return new R(200, page);
    }


    @PostMapping("/save")
    public R saveQuota(@RequestBody TbAlarmModel tbAlarmModel) {
         tbAlarmModelService.save(tbAlarmModel);
        return new R(200, "添加指标成功");
    }


    @PostMapping("/update")
    public R updateQuota(@RequestBody TbAlarmModel tbAlarmModel) {
        if (tbAlarmModelService.updateById(tbAlarmModel)) {
            return new R(200, "修改指标成功");
        } else {
            return new R(200, "修改指标失败");
        }
    }



    @GetMapping("/remove/{id}")
    public R removeQuota(@PathVariable("id") Integer id) {
        if (tbAlarmModelService.removeById(id)) {
            return new R(200, "删除指标成功");
        } else {
            return new R(200, "删除指标失败");
        }
    }

    @GetMapping("/info/{id}")
    public TbAlarmModel queryNumberQuota(@PathVariable("id") Integer id) {
        return tbAlarmModelService.getById(id);
    }

























    @PostMapping(value = "/saveOrUpdate")
    @ApiOperation(value = "保存或更新")
    public R saveOrUpdate(@RequestBody TbAlarmModel tbAlarmModel) {
        boolean val = tbAlarmModelService.saveOrUpdate(tbAlarmModel);
        return new R(200, val);
    }
}
